package com.tiancheng.trade.settlement.bo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tiancheng.trade.settlement.enums.OrderSourceEnum;
import com.tiancheng.trade.settlement.model.settlement.CouponBill;
import com.tiancheng.trade.settlement.util.AmountUtil;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 优惠券账单导出
 *
 * @author likailun
 */
@Data
public class CouponBillExportBO {
    /**
     * 主订单号
     */
    private String orderId;
    /**
     * 支付流水号
     */
    private String payFlowId;
    /**
     * 渠道订单号
     */
    private String transactionId;

    /**
     * 主订单名称
     */
    private String orderName;
    /**
     * 主商户编号
     */
    private String merchantCode;
    /**
     * 主商户名称
     */
    private String merchantName;
    /**
     * 支付渠道类型
     */
    private String payChannel;
    /**
     * 业务渠道来源
     */
    private String orderSourceCn;
    /**
     * 订单应收金额
     */
    private BigDecimal orderAmountYuan;
    /**
     * 订单支付总金额
     */
    private BigDecimal payAmountYuan;
    /**
     * 优惠金额
     */
    private BigDecimal discountYuan;
    /**
     * 平台优惠金额
     */
    private BigDecimal platformDiscountYuan;
    /**
     * 渠道优惠金额
     */
    private BigDecimal channelDiscountYuan;
    /**
     * 支付时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime payTime;

    /**
     * 券批次
     */
    private String couponBatchId;
    /**
     * 卡券号
     */
    private String couponNo;
    /**
     * 可用开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime availableStartTime;
    /**
     * 可用结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime availableEndTime;
    /**
     * 使用门槛
     */
    private String minimum;
    /**
     * 1-微信代金券，2-平台优惠券，3-其他
     */
    private String couponTypeName;

    public static CouponBillExportBO build(CouponBill source) {
        CouponBillExportBO target = new CouponBillExportBO();
        BeanUtils.copyProperties(source, target);
        target.setOrderSourceCn(OrderSourceEnum.getDesc(source.getOrderSource()));

        target.setOrderAmountYuan(AmountUtil.getYUAN(source.getOrderAmount()));
        target.setPayAmountYuan(AmountUtil.getYUAN(source.getPayAmount()));
        target.setDiscountYuan(AmountUtil.getYUAN(source.getDiscount()));
        target.setPlatformDiscountYuan(AmountUtil.getYUAN(source.getPlatformDiscount()));
        target.setChannelDiscountYuan(AmountUtil.getYUAN(source.getChannelDiscount()));
        target.setCouponTypeName(source.getCouponType().equals(1)?"微信代金券":"平台优惠券");
        return target;
    }
}
